/**
 *	\file
 *	\brief represents a single cell of the hash table containing the classes
 *
 * 	\date Sep 24, 2013
 * 	\author koldar
 *	\version 1.0
 */

#ifndef CLASSHTCELL_H_
#define CLASSHTCELL_H_

#include "uthash.h"
#include "ClassElement.h"

/**indicates a single cell of an hash table storing classes
 *
 */
typedef struct ClassHTCell {
	char* key; //!< represents the key of a class aka its name
	PclassElement class; //!< represents the class to be stored
	UT_hash_handle hh;
} ClassHTCell;

/**pointer to a cell
 *
 */
typedef ClassHTCell* PclassHTCell;

/**initialize correctly an hashtable cell. It can be freed with freeClassHTCell().
 *
 * \pre
 *  \li _class not NULL
 * \post
 *  \li a new element of the hash table that can be added to it;
 *  \li the key of this element points to the field "name" of the class set as value
 *
 * @param _class the structure to be decorated to be an hash table cell
 * @return a pointer to the newly created ClassHTCell
 */
PclassHTCell initClassHTCell(PclassElement _class);

/**Frees correctly a hash table cell
 *
 * \pre
 *  \li pcell must not be NULL
 * \post
 *  \li pcell is correctly freed from memory
 *
 * @param pcell the cell to be deallocated
 */
void freeClassHTCell(PclassHTCell pobj);

/**print a string representation of this hash table cell
 *
 * \pre
 *  \li f open in write mode;
 *  \li pcell not NULL;
 * \post
 *  \li f changed;
 *  \li in f the cell is represented by the expression: "[ key -> value ]"
 *
 * @param f the file to write on
 * @param pcell the cell to write
 */
void printClassHTCell(FILE* f, PclassHTCell pcell);

/**writes in f a code block that can be interpreted as a node in DOT language.
 * This function should be used to automatically generate DOT file representing
 * a local resource hash table.
 *
 * \pre
 *  \li f open in write mode;
 * \post
 *  \li in f there is a piece of code <b>not</b> immidiately compilable by dot;
 *  \li in f there is a piece of code representing this cell;
 *
 *
 * @param f the file to write on
 * @param pcell the cell to write
 * @param nodenumber the number of the dot node identifier. For example if you pass 53 then the ID will be n053. The regex is n%03d
 */
void generateDOTClassHTCell(FILE* f,PclassHTCell pcell,int* start);

#endif /* CLASSHTCELL_H_ */
